<form id="dailySubmit-form" lay-filter="dailySubmit-form" class="layui-form model-form">
    <input name="id" type="hidden"/>
    <div class="layui-form-item">
        <label class="layui-form-label">用户ID</label>
        <div class="layui-input-block">
            <input id="userId" name="userId" class="layui-input" readonly="readonly" style="border-color: white;outline: none;border: 0">
        </div>

    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">用户名称</label>
        <div class="layui-input-block">
            <input id="uname" name="uname" class="layui-input" readonly="readonly" style="border-color: white;outline: none;border: 0">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">日报内容</label>
        <div class="layui-input-block">
            <textarea id="content" name="content"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">提交方式</label>
        <div class="layui-input-block">
            <input type="radio" name="state" value="1" title="直接提交" checked/>
            <input type="radio" name="state" value="2" title="草稿箱"/>
        </div>
    </div>
    <div class="layui-form-item model-form-footer">
        <button class="layui-btn layui-btn-primary" ew-event="closeDialog" type="button">取消</button>
        <button class="layui-btn" lay-filter="dailySubmit-form-submit" lay-submit>保存</button>
    </div>
</form>

<script>
    layui.use(['form', 'table', 'util', 'config', 'index','admin','layedit'], function () {
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var layer = layui.layer;
        var util = layui.util;
        var index = layui.index;
        var admin = layui.admin;
        let userinfo = "";
        var layedit=layui.layedit;

        var content=layedit.build("content");

        index.getUser(function (user) {
            userinfo=user;
        });
        //用户信息赋值
        $("#userId").val(userinfo.id);
        $("#uname").val(userinfo.username);

        form.render('radio');
        //获取值
        var daily = admin.getTempData('t_daily');

        //修改赋值
        if (daily){
            $("#userId").val(daily.userId);
            $("#uname").val(daily.uname);
            layedit.setContent(content,daily.conten,false);
            $("input[name='state'][value='" + daily.state + "']").attr("checked", true);
            form.render();
            console.log(daily,333333);
        }else{
            console.log(daily,44444);
            daily={
                id:null
            }
            console.log(daily.id,55555);
        }


        // form.val('user-form', user);
        // 表单提交事件
        form.on('submit(dailySubmit-form-submit)', function (data) {
            layer.load(2);

            let res={
                id:daily.id,
                userId:data.field.userId,
                uname:data.field.uname,
                conten:layedit.getContent(content),
                state:data.field.state,
            };

            admin.req('api-sign/daily/dailySubmitOrUpdate', JSON.stringify(res), function (data) {
                layer.closeAll('loading');
                console.log(data);
                if (data.code == 0) {
                    layer.msg(data.msg, {icon: 1, time: 500});
                    admin.finishPopupCenter();
                } else {
                    layer.msg(data.msg, {icon: 2, time: 500});
                }
            }, "POST");

            return false;
        });
    });
</script>